package com.itmk.web.goods_comment.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itmk.utils.ResultUtils;
import com.itmk.utils.ResultVo;
import com.itmk.web.goods.entity.Goods;
import com.itmk.web.goods.service.GoodsService;
import com.itmk.web.goods_comment.entity.GoodsComment;
import com.itmk.web.goods_comment.service.GoodsCommentService;
import com.itmk.web.wx_user.entity.WxUser;
import com.itmk.web.wx_user.service.WxUserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/comment")
public class GoodsCommentController {
    @Autowired
    private GoodsCommentService goodsCommentService;
    @Resource
    private GoodsService goodsService;
    @Resource
    private WxUserService wxUserService;

    //新增评论
    @PostMapping("/addComment")
    public ResultVo addComment(@RequestBody GoodsComment goodsComment){
        Goods goods = goodsService.getById(goodsComment.getGoodId());
        if (goods!=null){
            GoodsComment goodsC = new GoodsComment();
            BeanUtils.copyProperties(goodsComment,goodsC);
            goodsC.setGoodId(goodsComment.getGoodId());
            goodsC.setCreateTime(new Date());
            goodsC.setUserId(goodsComment.getUserId());
            goodsCommentService.save(goodsC);
        }
        return ResultUtils.success("评论成功");
    }
    //小程序评论列表
    @GetMapping("/commentList")
    public ResultVo commentList(Long goodId){
        List<GoodsComment> list = goodsCommentService.commentList(goodId);
        return ResultUtils.success("查询成功",list);
    }
}
